package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Dianpu;
import com.ruoyi.system.service.IDianpuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 店铺Controller
 * 
 * @author ruoyi
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/system/dianpu")
public class DianpuController extends BaseController
{
    @Autowired
    private IDianpuService dianpuService;

    /**
     * 查询店铺列表
     */
    @PreAuthorize("@ss.hasPermi('system:dianpu:list')")
    @GetMapping("/list")
    public TableDataInfo list(Dianpu dianpu)
    {
        startPage();
        List<Dianpu> list = dianpuService.selectDianpuList(dianpu);
        return getDataTable(list);
    }

    /**
     * 导出店铺列表
     */
    @PreAuthorize("@ss.hasPermi('system:dianpu:export')")
    @Log(title = "店铺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Dianpu dianpu)
    {
        List<Dianpu> list = dianpuService.selectDianpuList(dianpu);
        ExcelUtil<Dianpu> util = new ExcelUtil<Dianpu>(Dianpu.class);
        util.exportExcel(response, list, "店铺数据");
    }

    /**
     * 获取店铺详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dianpu:query')")
    @GetMapping(value = "/{dpId}")
    public AjaxResult getInfo(@PathVariable("dpId") Long dpId)
    {
        return success(dianpuService.selectDianpuByDpId(dpId));
    }

    /**
     * 新增店铺
     */
    @PreAuthorize("@ss.hasPermi('system:dianpu:add')")
    @Log(title = "店铺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dianpu dianpu)
    {
        return toAjax(dianpuService.insertDianpu(dianpu));
    }

    /**
     * 修改店铺
     */
    @PreAuthorize("@ss.hasPermi('system:dianpu:edit')")
    @Log(title = "店铺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dianpu dianpu)
    {
        return toAjax(dianpuService.updateDianpu(dianpu));
    }

    /**
     * 删除店铺
     */
    @PreAuthorize("@ss.hasPermi('system:dianpu:remove')")
    @Log(title = "店铺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dpIds}")
    public AjaxResult remove(@PathVariable Long[] dpIds)
    {
        return toAjax(dianpuService.deleteDianpuByDpIds(dpIds));
    }
}
